<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <input type="text" placeholder="商品名称">
        <input type="text" placeholder="商品价格">
        <input type="text" placeholder="商品图片">
        <input type="text" placeholder="商品描述">
        <input type="button" value="保存" onclick="saveFn()">
    </div>
    <script src="../js/axios.min.js"></script>
    <script src="../js/api.js"></script>
    <script>
        let ipts = document.querySelectorAll("input");
        console.log(location.search);
        let obj = new URLSearchParams(location.search);
        console.log(obj.get("pid"));
        let pid = obj.get("pid");
        axios.get(productDetailAPI, {params:{id: pid}
        }).then(res=>{
            let {data} = res;
            console.log(data);
            ipts[0].value = data.data.pname;
            ipts[1].value = data.data.pprice;
            ipts[2].value = data.data.pimg;
            ipts[3].value = data.data.pdesc;
        })

        async function saveFn(){
            let pname = ipts[0].value;
            let pprice = ipts[1].value;
            let pimg = ipts[2].value;
            let pdesc = ipts[3].value;
            let params = {pname, pprice, pimg, pdesc, pid};
            let {data} = await axios.get(productUpdateAPI, {params});
            console.log(data);
            location.href = "index.html"
        }
    </script>
</body>
</html>